package com.haofengsoft.scce.adapter.quotations;

import java.util.List;

import com.haofengsoft.scce.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ShangHaiAdapter extends BaseAdapter {

	Context context;
	List<ShangHaiModel> shangHaiModelList;

	public ShangHaiAdapter(Context context, List<ShangHaiModel> shangHaiModelList) {
		this.shangHaiModelList = shangHaiModelList;
		this.context = context;
	}

	@Override
	public int getCount() {
		return shangHaiModelList.size();
	}

	@Override
	public Object getItem(int position) {
		return shangHaiModelList.get(position);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertview, ViewGroup parent) {
		View view = null;
		if (convertview == null) {
			view = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.quotations_shanghai_variety_gv_item,
					parent, false);
		} else {
			view = (ViewGroup) convertview;
		}
		TextView varietyNameTv = (TextView) view.findViewById(R.id.quotations_shanghai_item_variety_name_tv);
		TextView varietyUpAndDownTv = (TextView) view.findViewById(R.id.quotations_shanghai_item_variety_up_down_tv);
		TextView stampNameTv = (TextView) view.findViewById(R.id.quotations_shanghai_item_stamp_name_tv);
		TextView stampPriceTv = (TextView) view.findViewById(R.id.quotations_shanghai_item_stamp_price_tv);
		TextView stampUpAndDownTv = (TextView) view.findViewById(R.id.quotations_shanghai_item_stamp_up_down_tv);

		ShangHaiModel shangHaiModel = (ShangHaiModel) getItem(position);
		varietyNameTv.setText(shangHaiModel.getVarietyName());
		varietyUpAndDownTv.setText(shangHaiModel.getVarietyUpAndDown());
		stampNameTv.setText(shangHaiModel.getStampName());
		stampPriceTv.setText(shangHaiModel.getStampPrice());
		stampUpAndDownTv.setText(shangHaiModel.getStampUpAndDown());
		if (shangHaiModel.isVarietyUpOrDown()) {
			varietyUpAndDownTv.setTextColor(context.getResources().getColor(R.color.common_rise));
		} else {
			varietyUpAndDownTv.setTextColor(context.getResources().getColor(R.color.common_down));
		}

		return view;
	}

}
